﻿
using Chain.BLL;
using Chain.Model;
//    using ChainStock.Controls;
using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Expense : PageBase
{


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            Chain.BLL.OrderTime bllTime = new Chain.BLL.OrderTime();
            Chain.Model.OrderTime model = new Chain.Model.OrderTime();
            this.txtEndTime.Value = DateTime.Now.ToString();
            if (base.Request.QueryString["OrderCode"] != null)
            {
                DataTable dt = bllTime.GetList(" OrderTimeCode='" + base.Request.QueryString["OrderCode"].ToString() + "'").Tables[0];
                model = bllTime.GetModel(int.Parse(dt.Rows[0]["OrderTimeID"].ToString()));
                TimeSpan ts = DateTime.Now.Subtract(Convert.ToDateTime(model.OrderMarchTime));
                this.txtProject.Value = model.OrderProjectID.ToString();
                int allminute = 0;
                try
                {
                    Chain.Model.Timingrules mdTimingrules = new Chain.BLL.Timingrules().GetModel(Convert.ToInt32(dt.Rows[0]["OrderRulesID"]));
                    int minute = ts.Minutes + ((ts.Hours + (ts.Days * 0x18)) * 60);
                    allminute = minute;
                    int micount = minute / mdTimingrules.RulesInterval;
                    int passtime = minute % mdTimingrules.RulesInterval;
                    if (micount > 0)
                    {
                        if (passtime > mdTimingrules.RulesExceedTime)
                        {
                            micount++;
                        }
                    }
                    else
                    {
                        micount = 1;
                    }
                    this.txtExpMoney.Value = (mdTimingrules.RulesUnitPrice * micount).ToString("F2");
                    this.txtDiscountMoney.Value = this.txtExpMoney.Value;
                    this.JSXF.Value = "1";
                    this.txtExpMoney.Attributes["readonly"] = "readonly";
                    this.txtDiscountMoney.Attributes["readonly"] = "readonly";
                    this.txtExpPoint.Attributes["readonly"] = "readonly";
                }
                catch
                {
                }
                if (bool.Parse(base.Request.QueryString["IsMem"]))
                {
                    if (base.Request.QueryString["MemCard"] != null)
                    {
                        this.MemCard.Value = base.Request.QueryString["MemCard"];
                    }
                }
                else
                {
                    this.MemCard.Value = "0";
                }
                this.lblOrderAccount.InnerText = base.Request.QueryString["OrderCode"];
                this.txtExpPoint.Value = "0";
                this.spTimeInfo.InnerHtml = string.Concat(new object[] { "开始时间：", model.OrderMarchTime, "  结束时间：", DateTime.Now.ToString(), "消费时长：", ts.Hours + (ts.Days * 0x18), "小时 ", ts.Minutes, "分钟 ", ts.Seconds, "秒<br>总共：", allminute, "分钟" });
                this.txtIsTimeExpense.Value = "1";
                this.chkSMS.Checked = base.curParameter.bolMoneySms && base.curParameter.bolAutoSendSMSByTimingConsumption;
                this.lblIsSMS.Style.Add("display", (base.curParameter.bolMoneySms && base.curParameter.bolAutoSendSMSByTimingConsumption) ? "\"\"" : "none");
            }
            else
            {
                this.trTimeExpense.Attributes.Add("style", "display:none;");
                if (base.Request.QueryString["MemCard"] != null)
                {
                    this.MemCard.Value = base.Request.QueryString["MemCard"];
                }
                this.txtIsTimeExpense.Value = "0";
                this.lblOrderAccount.InnerText = base.curParameter.strExpensePrefix + DateTime.Now.ToString("yyMMddHHmmssffff");
                this.chkSMS.Checked = base.curParameter.bolMoneySms && base.curParameter.bolAutoSendSMSByFastConsumption;
                this.lblIsSMS.Style.Add("display", (base.curParameter.bolMoneySms && base.curParameter.bolAutoSendSMSByFastConsumption) ? "\"\"" : "none");
                this.ucMemberSearch.BolSenseICCard = base.curParameter.bolSenseiccard;
                this.ucMemberSearch.BolContactICCard = base.curParameter.bolContacticcard;
            }
            this.lblOrderCreateTime.InnerText = DateTime.Now.ToString();
            this.lblOrderUSer.InnerText = PubFunction.UserIDTOName(base._UserID);
            PubFunction.Get_PrintTitle(ref this.lblPrintTitle, ref this.lblPrintFoot, base._UserShopID);
            this.chkIsSMS.Checked = base.curParameter.bolSms;
            this.chkPrint.Checked = base.curParameter.bolAutoPrint;
            this.chkAllowPwd.Checked = base.curParameter.bolPwd;
            this.PointNum.Value = PubFunction.GetPointNum("KSXF");

            Get_ParameterList();
        }
    }


    private void Get_ParameterList()
    {
        Chain.BLL.Activity ActivityBll = new Chain.BLL.Activity();
        DataTable dt = ActivityBll.ActivityShow();

        foreach (DataRow dr in dt.Rows)
        {

            ActivityID.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));

        }

    }
}


